package com.example.base_lib.event_bus

import androidx.lifecycle.MutableLiveData

/**
 * 事件总线工具类
 */
object LiveDataBus {
    private val bus: MutableMap<String, MutableLiveData<Any>> =
        HashMap()

    @Synchronized
    @Suppress("UNCHECKED_CAST")
    fun <T> with(key: String, type: Class<T>?): MutableLiveData<T> {
        if (!bus.containsKey(key)) {
            bus[key] = MutableLiveData()
        }
        return bus[key] as MutableLiveData<T>
    }
}